package com.xiaodu.listener;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

/**
 * @author: dutianjie
 * @date: 2021/4/15
 * @version: v1.0.0
 * @description: 描述
 **/
@WebListener(value = "testListener")
public class MyServletContentListener implements ServletContextListener {

    private ServletContext servletContext;

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        System.out.println("listener init");
        this.servletContext = sce.getServletContext();
        servletContext.setAttribute("myListener", "attribute");
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        System.out.println("listener destroy");
    }
}
